<!--消息选项卡-->
<template>

  <div id="mainBody">
    <ul
      class="list-panel transparent-scroll-bar"
      ref="listController"
      v-if="msgList.length > 0"
    >

      <li
        class="row-panel"
        v-for="(item, index) in msgList"
        :key="item.id"
        @click="
          showChatInterface(
            item
          )
        "
        :class="{ active: currentIndex === index }"
      >
        <div></div>
        <el-badge class="item-avatar-panel" :value="item.totalUnread||''" :max="99">
          <div>
            <el-avatar :src="item.avatar" :alt="item.userName">
            </el-avatar>
          </div>
        </el-badge>

        <div class="item-nickname-panel">
          <div class="info">
            <div class="userName">{{ item.userName }}</div>
            <div class="subtitle">
              {{ item.lastMsgTxt ? item.lastMsgTxt : '暂无消息' }}
            </div>
          </div>
        </div>
        <div class="item-time-panel">
          <!--显示日期-->
          <div class="time">
            {{item.createTime}}
          </div>
        </div>
      </li>

    </ul>
    <div class="content-panel" ref="contentPanel">
      <img
        :src="contentPanel"
        alt="空组件"
        v-if="widgetIsNull"
      />
      <message-display
        v-else
        :message-status="messageType"
        :list-id="listId"
        :server-time="serverTime"
        :buddy-id="buddyId"
        :buddy-name="buddyName"
        @update-last-message="updateLastMessage($event)"
      />
    </div>
  </div>
</template>

<script>
  import messageDisplay from '@/components/Chat/message-display'

  export default {
    name: 'msg-list',
    components: {
      messageDisplay
    },
    methods: {
      showChatInterface(item) {
        console.log(item)
        this.widgetIsNull=false
      }
    },
    mounted() {
    },
    data() {
      return {
        contentPanel: require('@/assets/logo/tina.png'),
        msgSubscriptIco: require('@/assets/img/msg-subscript.png'),
        GroupBlocked: require('@/assets/img/Group_Blocked@2x.png'),
        lastMessageContent: '',
        currentIndex: -1, // 当前点击项索引
        widgetIsNull: true,
        listId: '',
        messageType: '',
        buddyId: '',
        serverTime: null,
        buddyName: '',
        msgList: [{
          id: 1,
          userName: 'Tinaaaaaaaaaaaa',
          buddyId: 9999,
          type: 1,
          totalUnread: 0,
          avatar: '/dev-api/profile/avatar/2021/06/21/ffc1d3b1-0465-4e33-a86b-0d72007a5cbe.jpeg',
          lastMsgTxt: '不知道那个帅sasssssssssssssssssss',
          createTime: '15:28'
        }, {
          id: 2,
          userName: 'Tina',
          buddyId: 9999,
          type: 1,
          totalUnread: 10,
          avatar: '/dev-api/profile/avatar/2021/06/21/ffc1d3b1-0465-4e33-a86b-0d72007a5cbe.jpeg',
          lastMsgTxt: '不知道那个帅sasssssssssssssssssss',
          createTime: '15:28'
        }]
      }
    },
    computed: {
      rightMenuObj() {
        // 右键菜单对象，菜单内容和处理事件
        const obj = {
          this: this,
          text: [
            '查看资料',
            { content: '复制用户id', status: true },
            '移除该会话',
            '在联系人中查看',
            '在单聊窗口中打开',
            '会话置顶'
          ],
          handler: {
            checkingData(parameter) {
              console.log(parameter)
              console.log(obj.this.$store.state.token)
              console.log('查看资料点击事件')
            },
            copyId() {
              console.log('复制用户id点击事件')
            },
            removeItem() {
              console.log('移除会话点击事件')
            },
            showContact() {
              console.log('在联系人中查看')
            },
            showSingleChat() {
              console.log('在单聊窗口中打开')
            },
            topConversation() {
              console.log('会话置顶')
            }
          }
        }
        return obj
      }
    }
  }
</script>

<style lang="scss" scoped>
  #mainBody {
    width: 100%;
    height: 100%;
    display: flex;

    .list-panel {
      min-width: 210px;
      width: 15%;
      height: 100%;
      box-sizing: border-box;
      border-right: solid 2px #f6f7f9;
      overflow-y: auto;
      padding: 0;

      .row-panel {
        width: 100%;
        height: 70px;
        list-style: none;
        background: #fdfdfd;
        cursor: pointer;
        user-select: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #f5f5f5;

        &:hover {
          background-color: #ebebeb;
        }

        .item-avatar-panel {
          margin-right: 10px;
        }

        .item-nickname-panel {
          width: 35%;
          min-width: 75px;
          height: 40px;

          div {
            font-size: 15px;
            overflow: hidden;
            /*溢出的部分隐藏*/
            white-space: nowrap;
            /*文本不换行*/
            text-overflow: ellipsis;
            line-height: 22px;

            &.userName {
              font-weight: 400;
            }

            &.subtitle {
              color: #7b7b7b;
              font-size: 12px;
            }
          }
        }

        .item-time-panel {
          min-width: 61px;
          width: 28%;
          height: 40px;
          display: flex;
          flex-wrap: wrap;
          justify-content: flex-end;
          align-items: flex-start;
          position: relative;

          & .time {
            width: 100%;
            font-size: 12px;
            color: #7b7b7b;
            text-align: right;
            margin-right: 1px;
          }

          /*未读消息条数显示样式*/
          .msg-count-panel {
            animation: msgChange 1s;
            background: #F55449;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: 300;
            font-size: 10px;
          }

          // 99+消息显示样式
          .msg-count-more-panel {
            animation: moreMsgChange 1s;
            border-radius: 50%;
            width: 18px;
            height: 17px;
          }

          // 免打扰显示样式
          .doNotDisturb-panel {
            width: 16px;
            height: 16px;
            position: absolute;
            bottom: 5px;
            right: 5px;

            img {
              width: 100%;
              height: 100%;
            }
          }
        }
      }

      .active {
        background-color: #E4E4E4;
      }

      .topping {
        background: #f3f3f3;
      }
    }

    .content-panel {
      width: 85%;
      // 设置最小宽度避免出现横向滚动条
      min-width: calc(100% - 214px);
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;

    }
  }

  // 显示未读消息时的过度动画
  @keyframes msgChange {
    from {
      width: 0;
      height: 0;
    }

    to {
      width: 20px;
      height: 20px;
      border-radius: 50%;
    }
  }


  // 未读消息超过9条时显示的过度动画
  @keyframes moreMsgChange {
    from {
      width: 20px;
      border-radius: 50%;
    }

    to {
      width: 40px;
      border-radius: 20px;
    }
  }
</style>
